define(['./plugins/dragValidate/drag.js'], function () {
    var $page = $(document.body);
    $page.find('form').fadeIn();

    var _options = {
        message: '此值无效',
        fields: {
            username: {
                message: '账号不符',
                validators: {
                    notEmpty: {
                        message: '账号为必填项'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: '账号长度必须大于6小于30'
                    },
                }
            },
            password: {
                message: '密码不符',
                validators: {
                    notEmpty: {
                        message: '密码为必填项'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: '密码长度必须大于6小于30'
                    },
                }
            }
        }
    };

    var formValidators = $page.find("form").bootstrapValidator(_options).on('error.form.bv', function (e) {
            console.log('error.form.bv');
            $("#dragValidate").empty().dragValidate({
                done: done
            });
        }).on('success.form.bv', function (e) {
            console.log('success.form.bv');
            // 提交表单
            setTimeout(function(){
                $page.find("form").ajaxSubmit({
                    url: './simdata/common_add_action.json',
                    // beforeSubmit: function (data) {
                    //     formValidators.data('bootstrapValidator').isValid()
                    // },
                    success: function (data, state, obj) {
                        window.location.href = './home.html';
                    },
                    error: function () {
                        toastr.options = {
                            "closeButton": true,
                            "debug": false,
                            "positionClass": "toast-top-full-width",
                            "onclick": null,
                            "showDuration": "300",
                            "hideDuration": "1000",
                            "timeOut": "5000",
                            "extendedTimeOut": "1000",
                            "showEasing": "swing",
                            "hideEasing": "linear",
                            "showMethod": "fadeIn",
                            "hideMethod": "fadeOut"
                        };
                        toastr['error']("登录失败，请刷新重试", "系统错误");
                        $("#dragValidate").empty().dragValidate({
                            done: done
                        });
                    }
                });
            },1000)

        })
        .on('error.field.bv', function (e, data) {
            console.log('error.field.bv -->', data);
        })
        .on('success.field.bv', function (e, data) {
            console.log('success.field.bv -->', data);
        });

    $("#dragValidate").dragValidate({
        done: done
    });
    function done(){
        $('form').bootstrapValidator('validate');
    }
});